package com.xiyoo.cw.common;

import com.xiyoo.cw.common.enums.ResultCode;
import lombok.Data;
import org.slf4j.MDC;

import java.io.Serializable;

/**
 * @Description:
 * @Date: 2024/6/18 10:55
 * @Author: xiyoo
 */
@Data
public class Result<T> implements Serializable {

    /**
     * 响应码
     */
    private Integer code;

    /**
     * 响应信息
     */
    private String msg;

    /**
     * 响应数据
     */
    private T data;

    /**
     * 请求流水号
     */
//    private String requestId;

    private static final String UNIQUE_ID_NAME = "traceId";

    public Result(T data) {
        this(ResultCode.SUCCESS, data);
    }

    public Result(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
//        this.requestId = MDC.get(UNIQUE_ID_NAME);
    }

    public Result(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = null;
//        this.requestId = MDC.get(UNIQUE_ID_NAME);
    }

    public Result(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
//        this.requestId = MDC.get(UNIQUE_ID_NAME);
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
        this.data = null;
//        this.requestId = MDC.get(UNIQUE_ID_NAME);
    }
}
